package com.prs.crm.service.cdxh.impl;


import java.io.File;
import java.io.Serializable;

import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.cdxh.CdstockDao;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.cdxh.Cdstock;
import com.prs.crm.domain.cdxh.cd_Product;
import com.prs.crm.domain.oa.Notice;
import com.prs.crm.service.cdxh.CdstockService;
import com.prs.crm.service.cdxh.cd_ProductService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.NoticeService;

public class CdstockServiceImpl extends BaseServiceImpl<Cdstock, CdstockDao> implements CdstockService {
	private NoticeService noticeService;
	
	private cd_Product cd_Product;
	
	private cd_ProductService cd_ProductService;
	
	@Override
	public void saveOrUpdate(Cdstock cdstock) {
		// TODO Auto-generated method stub
		this.getDao().saveOrUpdate(cdstock);
	}

	@Override
	public Cdstock getCdstockById(Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getCdstockById(id);
	}

	
	@Override
	public void submitCdstock(Cdstock cdstock,
			File file, String fileName) {
		// TODO Auto-generated method stub
		Attachment attach = FileUtil.getInstance().createAttach(file, fileName);
		if(attach != null) {
			cdstock.setAttach(attach);
		}
		cd_Product  perObject=this.getCd_ProductService().getProductObject(cdstock.getProductcode());
		perObject.setShowSafeConfigration(7);
		this.getCd_ProductService().saveOrProduct(perObject);	
		this.getDao().save(cdstock);
		
//		
//		if(cdstock.getAmount()!=null){
//		    if(cdstock.getAmount()>cdstock.getMax_amount()||cdstock.getAmount()<cdstock.getMin_amount()){			
//			String msg = "您的"+cdstock.getId()+cdstock.getRecordTime()+"与"+cdstock.getDescribes()+"的安全库存配置报警，请查看";
//			Notice notice = new Notice();
//			notice.setTitle("安全库存");
//			notice.setContent(msg);
//			notice.setStateID(cdstock.getId());
//			
//			this.getNoticeService().sendNotice(notice, cdstock.getRecorder());
//		    }
//		}

		
		
	}

	public NoticeService getNoticeService() {
		return noticeService;
	}

	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}

	@Override
	public Cdstock getCdstock(String productCode, String productName) {
		// TODO Auto-generated method stub
		return this.getDao().getCdstock(productCode, productName);
	}

	@Override
	public void saveOrStock(Cdstock cdStock) {
		// TODO Auto-generated method stub
		this.getDao().saveOrStock(cdStock);
	}

	public cd_Product getCd_Product() {
		return cd_Product;
	}

	public void setCd_Product(cd_Product cd_Product) {
		this.cd_Product = cd_Product;
	}

	public cd_ProductService getCd_ProductService() {
		return cd_ProductService;
	}

	public void setCd_ProductService(cd_ProductService cd_ProductService) {
		this.cd_ProductService = cd_ProductService;
	}





}
